import com.colodoo.code.entity.TableInf;
import org.apache.ibatis.jdbc.SQL;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.lang.reflect.Field;

public class SqlUtils {

	public static void main(String[] args) {

		SQL sql = new SQL();

		// TableInf
		// 表名
		Table table = TableInf.class.getAnnotation(Table.class);
		String tableName = table.name();
		System.out.println(tableName);

		Field[] fields = TableInf.class.getDeclaredFields();

		for (int i = 0; i < fields.length; i++) {
			Field field = fields[i];

			// 字段
			Column column = field.getAnnotation(Column.class);
			String columnName = column.name();

			sql.SELECT(columnName);
			sql.WHERE(columnName + " = #{" + columnName + "}");

			// ID
			Id id = field.getAnnotation(Id.class);
			if (id != null) {
				System.out.println(columnName + "是id" );
			}

			System.out.println(columnName);
		}

		sql.FROM(tableName);
		System.out.println(sql.toString());

	}

}
